package com.demo2do.fms.admin.dao.data;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.data.cost.OilPrice;

/**
 * 
 * @author Ysy
 *
 */
@Dao("hibernate")
public interface OilPriceDao {
    
    /**
     * 
     * @param orgIds
     * @return
     */
    @Query("SELECT count(*) FROM OilPrice price WHERE price.organization.id in (:orgIds)")
    public int count(@Variable("orgIds") List<Long> orgIds);
    
   /**
    * 
    * @param orgIds
    * @param beginIndex
    * @param maxResult
    * @return
    */
    @Limit
    @Query("FROM OilPrice price WHERE price.organization.id IN (:orgIds) ORDER BY price.organization ASC, price.effectDate DESC")
    public List<OilPrice> list(@Variable("orgIds") List<Long> orgIds, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param orgId
     * @param oilType
     * @return
     */
    @Query("FROM OilPrice price WHERE price.organization.id = :orgId AND  price.oilType = :oilType AND price.effectDate IS NOT NULL ORDER BY price.effectDate DESC")
    public OilPrice getOilPrice(@Variable("orgId")Long orgId, @Variable("oilType") Long oilType);
    
}
